# coding=utf-8
# 全世界最帅的帅哥
from celery import Celery

from ysgg1_club_celery import create_app

celery_app = Celery("ysgg1_club_celery",
                    broker="amqp://admin:admin@121.40.187.211//",
                    backend="redis://:ACceSsysgg1234@121.40.187.211:6379/3",
                    include=["ysgg1_club_celery.tasks"])

celery_app.conf.update(
    timezone="Asia/Shanghai",
    enable_utc=False,
    result_expires=3600
)

# 配置定时任务
celery_app.conf.beat_schedule = {
    'sync-liked-every-10-seconds': {
        'task': 'ysgg1_club_celery.tasks.sync_liked',
        'schedule': 10.0,  # 每 10 秒执行一次
    },
}


class ContextTask(celery_app.Task):
    def __call__(self, *args, **kwargs):
        app = create_app()
        with app.app_context():
            return self.run(*args, **kwargs)


celery_app.Task = ContextTask

if __name__ == '__main__':
    celery_app.start()
